package com.doublefish.doublefishrobot.ui.home.s5;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.doublefish.doublefishrobot.R;
import com.doublefish.doublefishrobot.base.BaseActivity;
import com.doublefish.doublefishrobot.ui.home.adapter.ModeCustomListAdapter;
import com.doublefish.doublefishrobot.ui.home.bean.ModeSettingBean;
import com.doublefish.doublefishrobot.utils.ble.bean.ModeConstant;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 作者:dugaofeng on 2024/12/30 10:35
 */
public class S5ModeTrainListActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView titleTv;

    @BindView(R.id.recycler_mode)
    RecyclerView recyclerView;

    private ModeCustomListAdapter adapter;
    private List<ModeSettingBean> beanList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mode_train_list_s5;
    }

    @Override
    protected void initView() {
        titleTv.setText(getString(R.string.trainning_mode));

        adapter = new ModeCustomListAdapter(this, beanList);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                ModeSettingBean bean = beanList.get(position);
                toTrainActivity(bean);
            }
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        //手动生成5个 模式
        // 这里需要对一些数据的进行调整
        //iOS在列表页面就已经调好了， Android由于Intent传值的问题，放到S5ModeTrainActivity来调整

        ModeSettingBean bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_1));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(1);
//        bean.setScript("0,0,3,3,4#0,0,3,3,8#");
        bean.setScript("0,0,3,3,4#");
	    beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_2));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(2);
//        bean.setScript("0,0,3,3,4#0,0,3,3,6#0,0,3,3,8#");
        bean.setScript("0,0,3,3,4#");
        beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_3));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(3);
//        bean.setScript("0,0,3,3,4#0,0,3,3,4#0,0,3,3,8#");
        bean.setScript("0,0,3,3,4#");
        beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_4));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(4);
//        bean.setScript("0,0,3,3,6#0,0,3,3,4#0,0,3,3,6#0,0,3,3,8#");
        bean.setScript("0,0,3,3,6#");
        beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_5));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(5);
//        bean.setScript("0,0,3,3,4#0,0,3,3,4#0,0,3,3,8#0,0,3,3,8#");
        bean.setScript("0,0,3,3,4#");
        beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_6));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(6);
        bean.setScript("0,0,3,3,6#");
        beanList.add(bean);

        bean = new ModeSettingBean();
        bean.setName(getString(R.string.s5_mode_7));
        bean.setProtocolType(ModeConstant.ProtocolTypeS5);
        bean.setMode(7);
//        bean.setScript("1,8,3,3,6#2,8,3,3,6#");
        bean.setScript("0,0,3,3,6#");
        beanList.add(bean);

        adapter.notifyDataSetChanged();
    }

    @Override
    protected void initListener() {

    }

    private void toTrainActivity(ModeSettingBean bean) {
        Intent intent = new Intent(this, S5ModeTrainActivity.class);
        intent.putExtra("bean", bean);
        startActivity(intent);
    }

    @OnClick(R.id.ll_back)
    public void onBackClick() {
        finish();
    }
}
